<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>云校通-教师-晚修辅导登记</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<body ontouchstart style="background:#fff;" class="js-jf">
	<div class="weui_tab tab-bottom">
      	<div class="weui-header bg-blue">
	  		<div class="weui-header-left"> <a onclick="back()" href="javascript:" class="icon icon-109 f-white">返回</a> </div>
	    	<h1 class="weui-header-title">${weekText } ${coachTypeText } 辅导登记</h1>
		</div>
		<div class="weui_tab_bd">
			<div class="searchbar_wrap mt10"></div>
			<div class="weui_cell lblue bd-t0 mt20"> 
	            <div class="weui_cell_bd weui_cell_primary">
	                <p class="">已到教师</p>
	            </div>
          	</div>
			<div class="name_show mt0">
				<ul></ul>
			</div>
			<div class="name_show_box">
				<ul>
				</ul>
			</div>
		</div>
    </div>
</body>
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
<script type="text/javascript">
	$(function() {
		initPlan();
		$(document).on("click",".operate",function(){
			operate($(this));
		})
		$('.searchbar_wrap').searchBar({
	        cancelText:"取消",
	        searchText:'请输入已到教师',
	        onfocus: function (value) {
	           $('.name_show_box').show();
	        },
	        onblur:function(value) {
	        		
	        },
	        input: function(value) {
	        	queryItem(value);
	        },
	        onsubmit:function(value){
	        	queryItem(value);
	        },
	        oncancel:function(){
	        	$('.name_show_box ul').html('');
	        	$('.name_show_box').hide();
	        },
	        onclear:function(){
	        	$('.name_show_box ul').html('');
	        	$('.name_show_box').hide();
	        }
	    });
		$(document).on("click", ".grid_add",function(){
	 		$('.hide_bd').attr("style", "display: block");
	 		$('.type1').show();
	 		$("#type").val($(this).attr("data-id"));
	 	});
		$('.last_li .cancel').click(function(){
    		$('.hide_bd').attr("style", "display: none");
    		$('.type1').hide();
    	});
	})
	
	var listMap = new Map();
	function initPlan() {
		$.ajax({
			url: basePath + "/ls/late/coach/getTodayNoComeList",
			type: 'POST',
			dataType : "json",
			data: {
				coachType: "${coachType}"
			},
			success: function(rspData) {
				var html = '';
				for(var i in rspData) {
					html += '<li onclick="listDel(this)" class="list-del" data-id="'+rspData[i].id+'" data-name="'+rspData[i].teacherName+'">'+rspData[i].teacherName+'<span class="list-del-vaild"></span></li>';
				}
				$('.name_show').find('ul').html(html);
			},
			error: function(data) {
				$.alert("系统异常,请联系管理员", "");
			}
		});
	}
	
	function listDel(thiz) {
		$.ajax({
			url: basePath + "/ls/late/coach/cancelReg",
			type: 'POST',
			dataType : "json",
			data: {
				id: $(thiz).attr("data-id")
			},
			success: function(resp) {
				if(resp.code == '000') {
					//$.toast("操作成功");
					initPlan();
				}else {
					$.toast(resp.msg, "cancel");
				}
			},
			error: function(data) {
				$.alert("系统异常,请联系管理员", "");
			}
		});
    }
    function searchPoint(thiz) {
    	var teacherName = $(thiz).attr("data-name");
   		var data = {
			week: "${week}",
			coachType: "${coachType}",
			teacherName: teacherName
		}
   		$.ajax({
   			url: basePath + "/ls/late/coach/addReg",
   			type: 'POST',
   			dataType : "json",
   			data: data,
   			success: function(resp) {
   				if(resp.code == '000') {
   					//$.toast("操作成功");
   					initPlan();
   					$('.name_show_box ul').html('');
   			    	$('.name_show_box').hide();
   			    	$("#weui_search_input").val(null);
   				}else {
   					$.toast(resp.msg, "cancel");
   				}
   			},
   			error: function(data) {
   				$.alert("系统异常,请联系管理员", "");
   			}
   		});
    }
    var search = false;
    function queryItem(keyword) {
 		if(!/^[\u4E00-\u9FA5]+$/.test(keyword)) return;
 		if(search) return;
 		search = true;
 		$.ajax({
     		url: basePath + "/ls/teacher/manage/keyword",
     		type: 'POST',
     		dataType : "json",
     		data: {
     			teacherName: keyword
     		},
     		success: function(data) {
     			search = false;
     			if (data != null && data.length > 0) {
     				var html = "";
     				for(var i in data) {
     					var itm = data[i];
     					html += "<li onclick='searchPoint(this)' data-id="+itm.id+" data-name="+itm.name+">"+itm.name+"</li>";
     				}
     				$(".name_show_box ul").html(html);
     			}
     		},
     		error: function(data) {
     			alert("系统异常,请联系管理员");
     		}
     	});
 	}
</script>
</html>